package com.practice.springboot_01_zwj.controller;

import com.practice.springboot_01_zwj.entity.CityRequest;
import com.practice.springboot_01_zwj.entity.ShangJi;
import com.practice.springboot_01_zwj.service.ShangJiService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/shangJi")
public class ShangJiController {
    @Autowired
    private ShangJiService shangJiService;
    @PostMapping
    public ResponseEntity<?> getMetrics(@RequestBody CityRequest request) {
        try {
            List<ShangJi> result = shangJiService.getMetricsByType(request.getType());
            return ResponseEntity.ok(result);
        } catch (IllegalArgumentException e) {
            return ResponseEntity.badRequest().body(e.getMessage());
        }
    }
}
